import unittest
from time import sleep
from appium import webdriver
from appium.options.android import UiAutomator2Options





class Swipe:
    def __init__(self,driver):
        self.driver=driver
        #获取屏幕分辨率
        self.size= self.driver.get_window_size()
        self.width = self.size.get("width")
        self.height = self.size.get("height")

    def swipe_up(self, duration=1):
        """向上滑动"""
        start_x = end_x = self.width / 2
        start_y = self.height * 0.8
        end_y = self.height * 0.2
        self.driver.swipe(start_x=start_x,
                          start_y=start_y,
                          end_x=end_x,
                          end_y=end_y,
                          duration=duration * 600)

    def swipe_down(self, duration=1):
        """向下滑动"""
        start_x = end_x = self.width / 2
        start_y = self.height * 0.2
        end_y = self.height * 0.8
        self.driver.swipe(start_x=start_x,
                          start_y=start_y,
                          end_x=end_x,
                          end_y=end_y,
                          duration=duration * 600)

    def swipe_left(self,duration=1):
        """向左滑动"""
        start_y = end_y = self.height / 2
        start_x = self.width * 0.8
        end_x = self.width * 0.2
        self.driver.swipe(start_x=start_x,
                          start_y=start_y,
                          end_x=end_x,
                          end_y=end_y,
                          duration=duration * 600)

    def swipe_right(self,duration=1):
        """向右滑动"""
        start_y = end_y = self.height / 2
        start_x = self.width * 0.2
        end_x = self.width * 0.8
        self.driver.swipe(start_x=start_x,
                          start_y=start_y,
                          end_x=end_x,
                          end_y=end_y,
                          duration=duration * 600)
